package com.auth.config.security;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 令牌增强实现类
 *  实现自定义参数添加
 * @author: hw
 * @date: 2020/12/9 16:57
 */
public class CustomTokenEnhancer implements TokenEnhancer{


    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {

        /**
         * 自定义参数
         */
        Map<String, Object> additionalInformation = new LinkedHashMap<>();
//        Map<String, Object> info = new LinkedHashMap<>();
//        additionalInformation.put("result", "200");
        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInformation);
        return accessToken;
    }

}
